//计算总额
var alltotal = 0;
function totalM() {
	$("#productlist .m_c_tab").each(function () {
		var strM = $(this).find(".o_jg").html();
		strM = strM.substring(strM.indexOf("￥") + 1);
		var strN = $(this).find(".o_p_num").html();
		strN = strN.substring(strN.indexOf("x") + 1);
		var total = parseFloat(strM) * parseInt(strN);
		alltotal += total;
	});
	alltotal = alltotal.toFixed(2);
	$("#sj_price").html("￥" + alltotal);
	$("#totalamount").html(alltotal);
	return alltotal;
};
//页面初始化加载
var totalprice=totalM();
//获取地址
$.ajax({
	url: 'Shop/Order/GetAddressInfo',
	data: {sjid:sjid},
	type: 'post',
	//contentType:"application/json;charset=utf-8",
	success: function (data) {
		// var result = JSON.parse(data);
		if (data) {
			$(".name").html(data.contactperson);
			$(".telephone").html(data.contacttel);
			$(".address_id").val(data.addressid);
			$(".address").html(data.address);
			var shwdjh = data.shwdjh.trim();
			if(shwdjh!="" && shwdjh!="无" && shwdjh!="待查"){
				$("#shwdjh").html(data.shwdjh);
				//$("#mod_shwdjh").show();
			}else{
				$("#in_shwdjh").show();
			}
		}
	}
});
//价格小数点后如果是1位就转换成2位
$(".o_jg").each(function() {
	var price = $(this).html().substring($(this).html().indexOf("￥") + 1);
	var p = parseFloat(price).toFixed(2);
	$(this).html(($(this).html().replace(price, p)));
})
$(".thfs").on("click",function(){
	$(".thfs .fp_fp").removeClass("fp_ck")
	$(this).find(".fp_fp").addClass("fp_ck");
})

var sizeLength = document.getElementsByClassName('size').length;
function checkOrder(){
	var flag = true;
	if(sizeLength > 0){
  		 if(!checkChoose(stylesList)){
  			 alert("请选择款式");
  			 flag = false; 
  			 return;
  		 }
  		 if(!checkChoose(sizesList)){
  			 alert("请选择尺码");
  			 flag = false; 
  			 return;
  		 }
	}
	if(chooseCount<sizeLength){
		alert("您还有"+(sizeLength-chooseCount)+"个赠送未选尺码");
		flag=false;
		return;
	}
  	if(sjid == 2){
  		//非整件商品总金额低于800
  		if(totalprice < 800){
  	        $(".jlgg").each(function(){
  	        	var number=parseInt($(this).parents(".m_c_tab").find(".num").val());
	        	if(number%parseInt(($(this).val()))!=0){
	        		alert("非整件商品总金额不能低于800元!");
	        		flag = false;
	        	  	return false;//跳出循环
	        	} 
  	        })
  		}
  	}else{
  		var bt_total = BtTotal();
  		if(bt_total < 1200){
			alert("抱团大包商品总金额不能低于1200元!");
			flag = false; 
			return;
	 	}
  		var shwdjh = $("#shwdjh").html() || $("#in_shwdjh").val();
  		if(shwdjh.trim() == "" || shwdjh == "无" || shwdjh == "待查"){
  			alert("请填写纳税人识别号！");
  			flag = false;
  			return;
  		}
  	}
  	return flag;
}

function BtTotal() {
	var bt_total = 0;
	var tab = $("#productlist .m_c_tab");
	tab.each(function () {
		var _this = $(this)
		var flbid = _this.find(".flbid").val();
		if(flbid == 2 || flbid == 4 || flbid == 114)return true;
		var strM = _this.find(".o_jg").html();
		strM = strM.substring(strM.indexOf("￥") + 1);
		var strN = _this.find(".o_p_num").html();
		strN = strN.substring(strN.indexOf("x") + 1);
		var total = parseFloat(strM) * parseInt(strN);
		bt_total += total;
	});
	bt_total = bt_total.toFixed(2);
	return bt_total;
};